#!/bin/bash
#
# chkconfig: - 98 02
# description: Starts and stops the your_prog_name daemon.

. /etc/init.d/functions

prog_name="your_prog_name"
prog_path="/path/to/${prog_name}"
prog_user="your_prog_user"
prog_conf="/path/to/your_prog_conf"
pidfile="/path/to/${prog_name}.pid"
options="-c ${prog_conf}"

lockfile="/var/lock/subsys/${prog_name}"

[ -x "${prog_path}" ] || exit 1
[ -r "${prog_conf}" ] || exit 1

start(){
  echo -n $"Starting ${prog_name}: "
  daemon --user ${prog_user} ${prog_path} ${options}
  retval=$?
  prog_pid=$(pidof ${prog_path})
  [ ! -z "${prog_pid}" ] && echo ${prog_pid} > ${pidfile}
  echo
  [ $retval -eq 0 ] && touch ${lockfile}
  return $retval
}

stop(){
  echo -n $"Stopping ${prog_name}: "
  killproc -p ${pidfile} ${prog_name}
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f ${lockfile}
  return $retval
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    sleep 1
    start
    ;;
  status)
    status -p ${pidfile} ${prog_name}
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 2
esac
exit $?
